package com.jingsheng.activity;

import com.jingsheng.corp.R;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class MainActivity extends TabActivity implements OnCheckedChangeListener{

	public MainActivity() {
		// TODO Auto-generated constructor stub
	}

	private TabHost mTabHost; 
    private Intent introductionIntent; 
    private Intent engineerIntent; 
    private Intent certificationIntent; 
    private Intent aboutIntent; 
    private Intent productsIntent; 
     
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        setContentView(R.layout.maintabs); 
         
        this.introductionIntent = new Intent(this,Introduction.class); 
        this.engineerIntent = new Intent(this,Engineer.class); 
        this.certificationIntent = new Intent(this,Certifications.class); 
        this.aboutIntent = new Intent(this,About.class); 
        this.productsIntent = new Intent(this,Products.class); 
         
        ((RadioButton) findViewById(R.id.radio_button0)) 
        .setOnCheckedChangeListener(this); 
        ((RadioButton) findViewById(R.id.radio_button1)) 
        .setOnCheckedChangeListener(this); 
        ((RadioButton) findViewById(R.id.radio_button2)) 
        .setOnCheckedChangeListener(this); 
        ((RadioButton) findViewById(R.id.radio_button3)) 
        .setOnCheckedChangeListener(this); 
        ((RadioButton) findViewById(R.id.radio_button4)) 
        .setOnCheckedChangeListener(this); 
         
        setupIntent(); 
    } 
 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        if(isChecked){ 
            switch (buttonView.getId()) { 
            case R.id.radio_button0: 
                this.mTabHost.setCurrentTabByTag("A_TAB"); 
                break; 
            case R.id.radio_button1: 
                this.mTabHost.setCurrentTabByTag("B_TAB"); 
                break; 
            case R.id.radio_button2: 
                this.mTabHost.setCurrentTabByTag("C_TAB"); 
                break; 
            case R.id.radio_button3: 
                this.mTabHost.setCurrentTabByTag("D_TAB"); 
                break; 
            case R.id.radio_button4: 
                this.mTabHost.setCurrentTabByTag("MORE_TAB"); 
                break; 
            } 
        } 
         
    } 
     
    private void setupIntent() { 
        this.mTabHost = getTabHost(); 
        TabHost localTabHost = this.mTabHost; 
 
        localTabHost.addTab(buildTabSpec("A_TAB", R.string.introduce, 
                R.drawable.introduce, this.introductionIntent)); 
 
        localTabHost.addTab(buildTabSpec("B_TAB", R.string.certifications, 
                R.drawable.certifications, this.certificationIntent)); 
 
        localTabHost.addTab(buildTabSpec("C_TAB", 
                R.string.products, R.drawable.products, 
                this.productsIntent)); 
 
        localTabHost.addTab(buildTabSpec("D_TAB", R.string.engineer, 
                R.drawable.engineer, this.engineerIntent)); 
 
        localTabHost.addTab(buildTabSpec("MORE_TAB", R.string.about, 
                R.drawable.about, this.aboutIntent)); 
 
    } 
     
    private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon, 
            final Intent content) { 
        return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel), 
                getResources().getDrawable(resIcon)).setContent(content); 
    } 
 
}
